package com.myrecycleview522lrx;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.converter.scalars.ScalarsConverterFactory;

/**
 * Created by Administrator on 2017/5/29.
 */

public class ResModel<T> implements LrxIface {
    private Retrofit retrofit;
    private ResService service;

    private static final String BASE_URL="http://amicool.neusoft.edu.cn/";

    public ResModel(String type) {
        if(type.equals("gson")){
            retrofit = new Retrofit.Builder().baseUrl(BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create()).build();
        }
        else{
            retrofit = new Retrofit.Builder().baseUrl(BASE_URL)
                    .addConverterFactory(ScalarsConverterFactory.create()).build();
        }
        service = retrofit.create(ResService.class);
    }
    @Override
    public void login(String u, String p, final LrxListener l) {
        Call<LoginBean> call = service.login(u,p);
        call.enqueue(new Callback<LoginBean>() {
            @Override
            public void onResponse(Call<LoginBean> call, Response<LoginBean> response) {
                l.onResponse(response.body());
            }

            @Override
            public void onFailure(Call<LoginBean> call, Throwable t) {
                l.onFail(t.toString());

            }
        });

    }

    @Override
    public void reg(String u, String p, String t, int roleid, String email, LrxListener l) {

    }

    @Override
    public void getList(String mod, int page, String s, LrxListener l) {

    }

    @Override
    public void getDetail(String mod, int id, String s, LrxListener l) {

    }
}
